#include <stdio.h>

void main()
{
	int i = 0, j = 0,n=0,k1=0, arr1[3][3] = { 0 }, arr2[3][3] = { 0 };


	scanf_s("%d", &n);

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			scanf_s("%d", &arr1[i][j]);
			arr2[i][j] = arr1[i][j];
		}

	}



	for (i = 1; i <= n; i++)
	{
		for (j = 0; j <= 2; j++)
		{
			arr2[j][2]=arr1[0][j];
		}
		for (j = 0; j <= 2; j++)
		{
			arr2[j][1]=arr1[1][j];
		}
		for (j = 0; j <= 2; j++)
		{
			arr2[j][0]=arr1[2][j];
		}

		   

		    for (k1 = 0; k1 < 3; k1++)
		    {
				for (j = 0; j < 3; j++)
				{
					arr1[k1][j] = arr2[k1][j];
				}
		    }

	}


	for (k1 = 0; k1 < 3; k1++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d ", arr2[k1][j]);
		}
		printf("\n");
	}




}
